package org.zty.service;

import java.util.ArrayList;
import java.util.List;

import org.zty.common.BasePage;
import org.zty.domain.Attr;
import org.zty.domain.Pojo;

public class ToPojoStr {
	private final static String importstr = "import org.zty.common.BasePage;\r\n";
	public String toPojoStr(Pojo pojo){
		StringBuffer sb = new StringBuffer();
		List<Attr> attrList = pojo.getAttrList();
		sb.append(importstr);
		sb.append("public class "+pojo.getName()+" extends BasePage{\r\n");
		for(Attr attr :attrList){
			sb.append("\tprivate ");
			if(attr.getType()==1){
				sb.append("String ");
			}else if(attr.getType()==2){
				sb.append("int ");
			}else if(attr.getType()==3){
				sb.append("Date ");
			}else{
				sb.append("*填写类型* ");
			}
			sb.append(attr.getName()+";\r\n");
		}
		sb.append("}");
		return sb.toString();
	}
	
	public static void main(String[] args) {
		ToPojoStr ts = new ToPojoStr();
		Pojo p = new Pojo();
		p.setName("Doc");
		Attr attr1=  new Attr();
		attr1.setName("id");
		attr1.setType(2);
		Attr attr2=  new Attr();
		attr2.setName("doctitle");
		attr2.setType(1);
		Attr attr3=  new Attr();
		attr3.setName("subtitle");
		attr3.setType(1);
		Attr attr4=  new Attr();
		attr4.setName("htmlcontent");
		attr4.setType(1);
		Attr attr5=  new Attr();
		attr5.setName("crtime");
		attr5.setType(3);
		Attr attr6=  new Attr();
		attr6.setName("doctime");
		attr6.setType(3);
		List l = new ArrayList<Attr>();
		l.add(attr1);
		l.add(attr2);
		l.add(attr3);
		l.add(attr4);
		l.add(attr5);
		l.add(attr6);
		p.setAttrList(l);
		System.out.println(ts.toPojoStr(p));
		
	}
}
